home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / floodp1r / connect.dsr (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-06  |  5.5 KB  |  136 lines

  1. VERSION 5.00
  2. Begin {AC0714F6-3D04-11D1-AE7D-00A0C90F26F4} Connect 
  3.    ClientHeight    =   10020
  4.    ClientLeft      =   1740
  5.    ClientTop       =   1545
  6.    ClientWidth     =   11295
  7.    _ExtentX        =   19923
  8.    _ExtentY        =   17674
  9.    _Version        =   393216
  10.    Description     =   "Provides a variety of useful functions to aid your Visual Basic development (okay, okay, just one for the moment)"
  11.    DisplayName     =   "Paladin"
  12.    AppName         =   "Visual Basic"
  13.    AppVer          =   "Visual Basic 98 (ver 6.0)"
  14.    LoadName        =   "Command Line / Startup"
  15.    LoadBehavior    =   5
  16.    RegLocation     =   "HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0"
  17.    CmdLineSupport  =   -1  'True
  18. Attribute VB_Name = "Connect"
  19. Attribute VB_GlobalNameSpace = False
  20. Attribute VB_Creatable = True
  21. Attribute VB_PredeclaredId = False
  22. Attribute VB_Exposed = True
  23. Option Explicit
  24. Public FormDisplayed          As Boolean
  25. Public VBInstance             As VBIDE.VBE
  26. Dim mcbMenuCommandBar         As Office.CommandBarControl
  27. Dim mfrmAddIn                 As New frmAddIn
  28. Public WithEvents MenuHandler As CommandBarEvents          'command bar event handler
  29. Attribute MenuHandler.VB_VarHelpID = -1
  30. Sub Hide()
  31.     On Error Resume Next
  32.     FormDisplayed = False
  33.     mfrmAddIn.Hide
  34. End Sub
  35. Sub Show()
  36.     On Error Resume Next
  37.     If mfrmAddIn Is Nothing Then
  38.         Set mfrmAddIn = New frmAddIn
  39.     End If
  40.     Set mfrmAddIn.VBInstance = VBInstance
  41.     Set mfrmAddIn.Connect = Me
  42.     FormDisplayed = True
  43.     mfrmAddIn.Show
  44. End Sub
  45. '------------------------------------------------------
  46. 'this method adds the Add-In to VB
  47. '------------------------------------------------------
  48. Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
  49.     On Error GoTo error_handler
  50.     'save the vb instance
  51.     Set VBInstance = Application
  52.     'this is a good place to set a breakpoint and
  53.     'test various addin objects, properties and methods
  54.     Debug.Print VBInstance.FullName
  55.     If ConnectMode = ext_cm_External Then
  56.         'Used by the wizard toolbar to start this wizard
  57.         Me.Show
  58.     Else
  59.         Set mcbMenuCommandBar = AddToAddInCommandBar("&Comment Out")
  60.         
  61.         'sink the event
  62.         Set Me.MenuHandler = VBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
  63.     End If
  64.     If ConnectMode = ext_cm_AfterStartup Then
  65.         If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  66.             'set this to display the form on connect
  67.             Me.Show
  68.         End If
  69.     End If
  70.     Exit Sub
  71. error_handler:
  72.     MsgBox Err.Description
  73. End Sub
  74. '------------------------------------------------------
  75. 'this method removes the Add-In from VB
  76. '------------------------------------------------------
  77. Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
  78.     On Error Resume Next
  79.     'delete the command bar entry
  80.     mcbMenuCommandBar.Delete
  81.     'shut down the Add-In
  82.     If FormDisplayed Then
  83.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
  84.         FormDisplayed = False
  85.     Else
  86.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
  87.     End If
  88.     Unload mfrmAddIn
  89.     Set mfrmAddIn = Nothing
  90. End Sub
  91. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  92.     If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  93.         'set this to display the form on connect
  94.         Me.Show
  95.     End If
  96. End Sub
  97. 'this event fires when the menu is clicked in the IDE
  98. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  99.     Dim StartLine As Long, StartColumn As Long, EndLine As Long, EndColumn As Long
  100.     VBInstance.ActiveCodePane.GetSelection StartLine, StartColumn, EndLine, EndColumn
  101.     If StartLine = EndLine And StartColumn = EndColumn Then Exit Sub
  102.     Dim Index As Long
  103.     Dim CommentOut As Boolean
  104.     For Index = StartLine To EndLine
  105.         If Index = EndLine And EndColumn = 1 Then Exit For
  106.         
  107.         If Index = StartLine Then
  108.             CommentOut = Left(VBInstance.ActiveCodePane.CodeModule.Lines(Index, 1), 1) <> "'"
  109.         End If
  110.         
  111.         If CommentOut Then
  112.             VBInstance.ActiveCodePane.CodeModule.ReplaceLine Index, "'" + VBInstance.ActiveCodePane.CodeModule.Lines(Index, 1)
  113.         Else
  114.             VBInstance.ActiveCodePane.CodeModule.ReplaceLine Index, Mid(VBInstance.ActiveCodePane.CodeModule.Lines(Index, 1), 2)
  115.         End If
  116.     Next
  117. End Sub
  118. Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  119.     Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
  120.     Dim cbMenu As Object
  121.     On Error GoTo AddToAddInCommandBarErr
  122.     'see if we can find the Add-Ins menu
  123.     Set cbMenu = VBInstance.CommandBars("Add-Ins")
  124.     If cbMenu Is Nothing Then
  125.         'not available so we fail
  126.         Exit Function
  127.     End If
  128.     'add it to the command bar
  129.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  130.     'set the caption
  131.     cbMenuCommandBar.Caption = sCaption
  132.     Set AddToAddInCommandBar = cbMenuCommandBar
  133.     Exit Function
  134. AddToAddInCommandBarErr:
  135. End Function
  136.